package com.passion;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 统一网关应用
 *
 * @author ZY
 */
@Slf4j
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = "com.passion.**")
@MapperScan("com.passion.domain.dao")
public class GatewayApplication {

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(GatewayApplication.class, args);
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        if (StringUtils.isEmpty(path)) {
            path = "";
        }
        String sslEnabled = env.getProperty("server.ssl.enabled");
        String protocol = "http";
        if (Boolean.TRUE.toString().equalsIgnoreCase(sslEnabled)) {
            protocol = "https";
        }
        log.info("\n----------------------------------------------------------\n" +
                "Spring Cloud Gateway is running! Access URLs:\n\t" +
                "Local访问网址: \t\t" + protocol + "://localhost:" + port + path + "\n\t" +
                "External访问网址: \t" + protocol + "://" + ip + ":" + port + path + "\n\t" +
                "聚合Swagger访问网址: \t" + protocol + "://localhost:" + port + path + "/doc.html\n" +
                "----------------------------------------------------------");
    }

}
